<?php
/**
 * Notes:
 * User: wudg <544038230@qq.com>
 * Date: 2025/9/9 16:36
 */

namespace App\Dao\Users;


use App\Constants\System\SysStatusConst;
use App\Dao\BaseDao;
use App\Model\Users\UserCategory;

class UserCategoryDao extends BaseDao
{


    /**
     * 获取类目详细
     * @param int $id
     * @return UserCategory|\Hyperf\Database\Concerns\BuildsQueries|\Hyperf\Database\Model\Builder|\Hyperf\Database\Model\Model|object|null
     */
    public function getCateById(int $id)
    {
        return UserCategory::query()->where('id','=',$id)->where('is_del','=',SysStatusConst::NORMAL->value)->first();
    }

    public function getCateByIds(array $ids,array $fields = [])
    {

        $model = UserCategory::query();

        if(!empty($fields)) $model->select($fields);
        return $model->whereIn('id',$ids)->where('is_del','=',SysStatusConst::NORMAL->value)->get()->toArray();
    }


    /**
     * 获取类目数量
     * @param int $uid
     * @return int
     */
    public function getCountCateNum(int $uid)
    {
        return UserCategory::query()->where('uid','=',$uid)->where('is_del','=',SysStatusConst::NORMAL->value)->count();
    }
}